//
//  ADCollectionViewModel.h
//  ADKit
//
//  Created by duzexu on 2018/4/4.
//

#import <ADKit/ADKit.h>

@class RACSignal,RACCommand;
@interface ADCollectionViewModel : ADViewModel<DZNEmptyDataSetSource,DZNEmptyDataSetDelegate,UICollectionViewDelegate, UICollectionViewDataSource, UICollectionViewDelegateFlowLayout>

@property (nonatomic, readonly, weak) UICollectionView *collectionView;

/// The data source of collection view.
@property (nonatomic, readonly, copy) NSMutableArray *dataSource;

/// collectionView style layout.
@property (nonatomic, readwrite, strong) UICollectionViewLayout *collectionViewLayout;

/// collectionView item size
@property (nonatomic, readwrite, assign) CGSize itemSize;

/// `collectionView` 的内容缩进，default is UIEdgeInsetsMake(64,0,0,0)，you can override it
@property (nonatomic, readwrite, assign) UIEdgeInsets contentInset;

/// `collectionView` 的位置缩进，default is UIEdgeInsetsMake(0,0,0,0)，you can override it
@property (nonatomic, readwrite, assign) UIEdgeInsets collectionViewInset;

/// 需要支持下来刷新 defalut is NO
@property (nonatomic, readwrite, assign) BOOL shouldPullDownToRefresh;
/// refreshHeader's class, defalut is MJRefreshNormalHeader
@property (nonatomic, readwrite, assign) Class refreshHeaderClass;
/// 需要支持上拉加载 defalut is NO
@property (nonatomic, readwrite, assign) BOOL shouldPullUpToLoadMore;
/// refreshFooter's class, defalut is MJRefreshAutoFooter
@property (nonatomic, readwrite, assign) Class refreshFooterClass;

/// 是否数据是多段 (It's effect tableView's dataSource 'numberOfSectionsInTableView:') defalut is NO
@property (nonatomic, readwrite, assign) BOOL shouldMultiSections;
/// 是否在上拉加载后的数据,dataSource.count < pageSize 提示没有更多的数据.default is NO 默认做法是数据不够时，隐藏mj_footer
@property (nonatomic, readwrite, assign) BOOL shouldEndRefreshingWithNoMoreData;

/// 是否缓存数据
@property (nonatomic, readwrite, assign) BOOL shouldCacheData;

/// 当前页 defalut is 1
@property (nonatomic, readwrite, assign) NSUInteger page;
/// 是否有更多数据
@property (nonatomic, readwrite, assign) BOOL noMoreData;

/// 选中命令 eg:  didSelectRowAtIndexPath:
@property (nonatomic, readwrite, strong) RACCommand *didSelectCommand;
/// 请求本地数据的命令
@property (nonatomic, readonly, strong) RACCommand *requestLocalDataCommand;
/// 请求服务器数据的命令
@property (nonatomic, readonly, strong) RACCommand *requestRemoteDataCommand;
/// 请求数据的信号，包括本地数据和服务器数据
@property (nonatomic, readonly, strong) RACSignal *requestDataSignal;

/// 刷新列表
@property (nonatomic, readonly, strong) RACSubject *reloadIndexPaths;

/// 网络是否可用
@property (nonatomic, readwrite, assign) BOOL networkReachable;

/** fetch the local data */
- (RACSignal *)fetchLocalData;

/// 请求数据map sub class can ovrride it
- (id (^)(id value))requestDataMapper;

/// 请求错误信息过滤
- (BOOL (^)(NSError *error))requestRemoteDataErrorsFilter;

/** request remote data or local data, sub class can override it
 *  page - 请求第几页的数据
 */
- (RACSignal *)requestRemoteDataSignalWithPage:(NSUInteger)page;

/// 请求结果处理 sub class can ovrride it
- (void)localDataProcess:(id)x;
- (void)remoteDataProcess:(id)x;
- (void)requestDataCompleted;

/**
 数据源刷新
 */
- (void)reloadDataSource;
- (void)reloadDataSourceWithIndexPath:(NSIndexPath *)indexPath;
- (void)reloadDataSourceWithIndexPaths:(NSArray *)indexPaths;

/// registTableViewCell, subclass can overwrite it ,call super
- (void)registCollectionViewCell:(UICollectionView *)collectionView;

/// dequeueReusableCell, subclass can overwrite it
- (NSString *)collectionView:(UICollectionView *)collectionView cellIdentifierForIndexPath:(NSIndexPath *)indexPath withObject:(id)object;

/// configure cell data, subclass can overwrite it
- (void)configureCell:(UICollectionViewCell *)cell atIndexPath:(NSIndexPath *)indexPath withObject:(id)object;

@end
